//
//  PortPackaging.m
//  NetworkingSevers
//
//  Created by WorkSpace on 4/1/14.
//
//

#import "PortPackaging.h"


@implementation PortPackaging
@synthesize baseServer;



-(void)getNonceMethod:(NSString *)method
        andController:(NSString *)controller
              andJson:(NSString *)json
                block:(ReceiveSuccess)receiveSuccess
            failblock:(ReceiveFailure)receiveFailure;
{
    self.baseServer = [[NetworkingSevers alloc]init];
    NSMutableDictionary *parsDictionary = [[NSMutableDictionary alloc]init];
    [parsDictionary setObject:ONLYCOOKIE forKey:@"apikey"];
    [parsDictionary setObject:method forKey:@"method"];
    [parsDictionary setObject:controller forKey:@"controller"];
    [parsDictionary setObject:json forKey:@"json"];
    [self.baseServer setRequestStyle:nil andSetPathString:nil andSetHeadString:nil andActionName:nil andSetMainDictionary:parsDictionary block:^(id json)
     {
         userDefaults = [NSUserDefaults standardUserDefaults];
         [userDefaults setObject:[json objectForKey:S_NONCE] forKey:S_NONCE];
         [userDefaults synchronize];
         receiveSuccess(json);
         
     }
     failblock:^(NSError *error)
     {
         receiveFailure(error);
     }];
}
-(void)getCookieName:(NSString *)name
             withpwd:(NSString *)pwd
               block:(ReceiveSuccess)receiveSuccess
           failblock:(ReceiveFailure)receiveFailure;
{
    userDefaults = [NSUserDefaults standardUserDefaults];
    self.baseServer = [[NetworkingSevers alloc]init];
    NSMutableDictionary *parsDictionary = [[NSMutableDictionary alloc]init];
    [parsDictionary setObject:@"auth/generate_auth_cookie" forKey:@"json"];
    [parsDictionary setObject:ONLYCOOKIE forKey:@"apikey"];
    [parsDictionary setObject:name forKey:@"username"];
    [parsDictionary setObject:pwd forKey:@"password"];
    [parsDictionary setObject:[userDefaults objectForKey:S_NONCE] forKey:@"nonce"];
    [self.baseServer setRequestStyle:nil andSetPathString:nil andSetHeadString:nil andActionName:nil andSetMainDictionary:parsDictionary block:^(id json)
     {
         receiveSuccess(json);
     }
      failblock:^(NSError *error)
     {
//         receiveFailure(error);
     }];
}
-(void)loginToCookie:(NSString *)cookie
               block:(ReceiveSuccess)receiveSuccess
           failblock:(ReceiveFailure)receiveFailure
{
    self.baseServer = [[NetworkingSevers alloc]init];
    NSMutableDictionary *parsDictionary = [[NSMutableDictionary alloc]init];
    [parsDictionary setObject:@"auth/validate_auth_cookie" forKey:@"json"];
    [parsDictionary setObject:ONLYCOOKIE forKey:@"apikey"];
    [parsDictionary setObject:cookie forKey:@"cookie"];
    [self.baseServer setRequestStyle:nil andSetPathString:nil andSetHeadString:nil andActionName:nil andSetMainDictionary:parsDictionary block:^(id json)
     {
         receiveSuccess(json);
     }
     failblock:^(NSError *error)
     {
         receiveFailure(error);
     }];
}

@end
